#!/usr/bin/perl

use strict;
use warnings;
use feature qw{say};

open my $fh_in, '<:utf8', 'jobs.txt';
open my $fh_out, '>:utf8', 'jobs_spreadsheet.txt';
open my $fh_out2, '>:utf8', 'jobs_post_html.txt';

print $fh_out "Date Seen\tLocation\tTitle\tDetails\n";

my %label;
my $c = 0;
my $googlead = do { local( $/ ) = my $file ; <DATA> } ;

while (<$fh_in>){
	chomp;
	my @field = split(/\t/);
	
	# limit by date
	my $date = $field[0];
	my @date = split(m!/!, $date);
	$date = $date[2] . $date[1] . $date[0];
	next unless  $date > 20110605;
	
	$c++;
	
	# fix label

	# process labels
	$label{$field[1]}++;
	
	# write output
	print $fh_out "$field[0]\t$field[1]\t$field[2]\t$field[4]\n";
	
	print $fh_out2 "<a href='$field[4]'><b>$field[2]</b></a> ($field[1])\n";
	print $fh_out2 "\n" if $c != 15;
	#print $fh_out2 "$googlead\n\n" if $c == 5;
	#print $fh_out2 "<!--more-->\n" if $c == 15;
	
}

# print $fh_out2 "\n" . 'All the <a href="http://goo.gl/uDhdM">openings indexed</a> so far.' . "\n";

close $fh_in;
close $fh_out;
close $fh_out2;

for my $key (keys (%label)){
	next if $key eq '';
	$key =~ s/,//;
	print $key . ",";
}




#=hyperlink(E3;"Details")

__DATA__
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2573084202620181";
/* MyMediumRectangle */
google_ad_slot = "5417434554";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script> <script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>